package com.learn.xueer.ui.viewmodel

import androidx.lifecycle.MutableLiveData
import com.learn.xueer.app.network.apiService
import com.learn.xueer.data.model.bean.HomeInfoResponse
import com.learn.xueer.data.model.bean.TextBookResponse
import com.learn.xueer.data.model.bean.TextBookUnitResponse
import com.learn.xueer.data.model.bean.UnitWordResponse
import com.learn.xueer.data.model.bean.WordInfoResponse
import me.hgj.jetpackmvvm.base.viewmodel.BaseViewModel
import me.hgj.jetpackmvvm.callback.databind.StringObservableField
import me.hgj.jetpackmvvm.ext.request
import me.hgj.jetpackmvvm.state.ResultState

class RequestHomeViewModel : BaseViewModel() {
    var homeResult = MutableLiveData<ResultState<HomeInfoResponse?>>()
    val textBooksImage = StringObservableField()
    val textBooksTitle = StringObservableField()
    val textBooksDesc = StringObservableField()
    val unitTitle = StringObservableField()
    val textBookResult = MutableLiveData<ResultState<MutableList<TextBookResponse>?>>()
    val textBookUnitResult = MutableLiveData<ResultState<MutableList<TextBookUnitResponse>?>>()
    val unitWordResult = MutableLiveData<ResultState<MutableList<UnitWordResponse>?>>()
    val wordInfoResult = MutableLiveData<ResultState<MutableList<WordInfoResponse>?>>()

    /// 跟读
    val wordImage = StringObservableField()
    val word = StringObservableField()
    val symbol = StringObservableField()
    val pretations = StringObservableField()
    val sentences = StringObservableField()

    fun homeInfoReq() {
        request(
            {
                apiService.getHomeConfig()
            },
            homeResult,
            true,
            "正在加载..."
        )
    }

    fun textBookReq() {
        request(
            {
                apiService.textBook()
            },
            textBookResult,
            false,
            ""
        )
    }

    fun textBookUnitReq(id: String) {
        request(
            {
                apiService.textBookUnit(id)
            },
            textBookUnitResult,
            false,
            ""
        )
    }

    fun unitWordReq(id: String) {
        request(
            {
                apiService.unitWord(id)
            },
            unitWordResult,
            false,
            ""
        )
    }

    fun wordInfoReq(id: String) {
        request(
            {
                apiService.wordInfo(id)
            },
            wordInfoResult,
            false,
            ""
        )
    }
}